package com.randb.easyhttp.func;

import com.randb.easyhttp.exception.ServerException;
import com.randb.easyhttp.model.ApiResult;

import io.reactivex.functions.Function;

/**
 * User: RandBII
 * Date: 2020/5/9
 * Description:
 */
public class HandleFunc<T> implements Function<ApiResult<T>, T> {

    @Override
    public T apply(ApiResult<T> result) throws Exception {
        if (result.isOk()) {
            return result.getData();
        } else {
            throw new ServerException(result.getCode(), result.getMessage());
        }
    }
}
